<?php

include_once "model/Table.php";
class accountModel {

    function __construct($pagesize = 12) {
        $this -> tbl_account = new Table("tbl_account");
        $this -> pagesize = $pagesize;
        $this -> pagecount = 1;
        $this -> mysqli = DAO::connect();
    }

    function __destruct() {
        if ($this -> mysqli) {
            $this -> mysqli -> close();
        }
    }

    function selectAccount($account) {
        $rows = array();
        if ($rows = $this -> tbl_account -> select("*", "WHERE Account='".$account."'")) {
            return $rows;
        }
    }

    function selectAccounts($page = 1) {
        $rows = array();
        if ($rows = $this -> tbl_account -> select("*", "", $this -> pagesize, $page)) {
            $this -> pagecount = $this -> tbl_account -> pageCount("*", $this -> pagesize);
            return $rows;
        }
    }

    function addAccount($Account, $Password, $Name, $Email, $Birthday, $Role, $Address, $Phone, $About)
     {         
         
        $data = array("Account" => $Account, "Password" => $Password, "Name" => $Name, "Email" => $Email, "Birthday" => $Birthday, "Role" => $Role, "Address" => $Address, "Phone" => $Phone, "About" => $About);        
        return $this -> tbl_account -> insert($data);
    }

    function modifyAccount($Account, $Password, $Name, $Email, $Birthday, $Role, $Address, $Phone, $About) {
        $data = array("Password" => $Password, "Name" => $Name, "Email" => $Email, "Birthday" => $Birthday, "Role" => $Role, "Address" => $Address, "Phone" => $Phone, "About" => $About);
        
        $this -> tbl_account -> update($data, "Account='".$Account."'");
		return $this->tbl_account->message;
    }

}
